package com.ktdaddy.controller.system;

import com.ktdaddy.request.CreateDeptReq;
import com.ktdaddy.request.UpdateDeptReq;
import com.ktdaddy.service.DeptService;
import com.ktdaddy.utils.ApiResponse;
import com.ktdaddy.vo.DeptVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: lujianhao
 * @Description: DeptController
 * @Date: 2021/7/22 3:11 下午
 */
@Api(value = "部门相关", tags = {"部门相关"})
@RequestMapping("/whale/system/dept")
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @ApiOperation(value = "部门列表查询",notes = "部门列表查询",httpMethod = "GET")
    @GetMapping("/getDeptList")
    public ApiResponse getDeptList(@RequestParam(value = "deptName",required = false) String deptName,
                                   @RequestParam(value = "status",required = false)Integer status){
        List<DeptVO> deptList = deptService.getDeptList(deptName,status);
        return ApiResponse.ok(deptList);
    }

    @ApiOperation(value = "创建部门",notes = "创建部门",httpMethod = "POST")
    @PostMapping("/createDept")
    public ApiResponse createDept(@RequestBody @Valid CreateDeptReq createDeptReq){
        deptService.createDept(createDeptReq);
        return ApiResponse.ok();
    }


    @ApiOperation(value = "更新部门",notes = "更新部门",httpMethod = "POST")
    @PostMapping("/updateDept")
    public ApiResponse updateDept(@RequestBody @Valid UpdateDeptReq updateDeptReq){
        deptService.updateDept(updateDeptReq);
        return ApiResponse.ok();
    }

    @ApiOperation(value = "删除部门",notes = "删除部门",httpMethod = "GET")
    @GetMapping("/deleteDept")
    public ApiResponse deleteDept(@RequestParam(value = "deptId") Integer deptId){
        deptService.deleteDept(deptId);
        return ApiResponse.ok();
    }



}
